package com.eco.fanliapp.controller.app;


import com.eco.fanliapp.common.base.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.service.ISyGoldExchangeService;
import lombok.Synchronized;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-08-07
 */
@RestController
@RequestMapping("/app/task")
public class SyGoldExchangeController extends BaseController {

    @Autowired
    private ISyGoldExchangeService iSyGoldExchangeService;


    //兑换规则
    @GetMapping("/gold/exchangeRules")
    @ResponseBody
    public ServerResponse getAppTaskGoldExchangeRules() {
        AppUser u = getAppUser();
        if(null == u) {
            return ServerResponse.createByErrorCodeMessage(301,"Token不正确");
        }
        return iSyGoldExchangeService.getAppTaskGoldExchangeRules(u.getUserId());
    }

    //兑换
    @PostMapping("/gold/exchange")
    @ResponseBody
    @Synchronized
    public ServerResponse getAppTaskGoldExchange(Integer exchangeNumber) {
        String remark = "老版本金币兑换";
        AppUser u = getAppUser();
        if(null == u) {
            return ServerResponse.createByErrorCodeMessage(301,"Token不正确");
        }
        return iSyGoldExchangeService.getAppTaskGoldExchange(u.getUserId(),exchangeNumber,remark);
    }

}
